package com.ruoyi.shop.emporium.category.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.common.domain.DtsCategory;
import com.ruoyi.shop.emporium.category.service.IDtsCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品类目Controller
 *
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/emporium/category")
public class DtsCategoryController extends BaseController
{
    @Autowired
    private IDtsCategoryService dtsCategoryService;

    /**
     * 查询商品类目列表
     */
    @PreAuthorize("@ss.hasPermi('emporium:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtsCategory dtsCategory)
    {
        startPage();
        List<DtsCategory> list = dtsCategoryService.selectDtsCategoryList(dtsCategory);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('emporium:category:parentCategories')")
    @GetMapping("/parentCategories")
    public List<DtsCategory> getParentCategories() {
        return dtsCategoryService.selectDtsCategoryListByPid();
    }

    @PreAuthorize("@ss.hasPermi('emporium:category:parentCategorie')")
    @GetMapping("/parentCategorie")
    public List<DtsCategory> getParentCategorie(DtsCategory dtsCategory) {
        return dtsCategoryService.selectDtsCategoryListByCate(dtsCategory);
    }

    /**
     * 导出商品类目列表
     */
    @PreAuthorize("@ss.hasPermi('emporium:category:export')")
    @Log(title = "商品类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtsCategory dtsCategory)
    {
        List<DtsCategory> list = dtsCategoryService.selectDtsCategoryList(dtsCategory);
        ExcelUtil<DtsCategory> util = new ExcelUtil<DtsCategory>(DtsCategory.class);
        util.exportExcel(response, list, "商品类目数据");
    }

    /**
     * 获取商品类目详细信息
     */
    @PreAuthorize("@ss.hasPermi('emporium:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dtsCategoryService.selectDtsCategoryById(id));
    }

    /**
     * 新增商品类目
     */
    @PreAuthorize("@ss.hasPermi('emporium:category:add')")
    @Log(title = "商品类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtsCategory dtsCategory)
    {
        return toAjax(dtsCategoryService.insertDtsCategory(dtsCategory));
    }

    /**
     * 修改商品类目
     */
    @PreAuthorize("@ss.hasPermi('emporium:category:edit')")
    @Log(title = "商品类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtsCategory dtsCategory)
    {
        return toAjax(dtsCategoryService.updateDtsCategory(dtsCategory));
    }

    /**
     * 删除商品类目
     */
    @PreAuthorize("@ss.hasPermi('emporium:category:remove')")
    @Log(title = "商品类目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(dtsCategoryService.deleteDtsCategoryByIds(ids));
    }
}






















